package com.cxf.util;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class DBOperation {
	static Connection con =DBHelper.getConnection();
	public static ResultSet query(String sql,List<Object> param) { //��ѯ����
		
		PreparedStatement pre = null;
		ResultSet resultSet = null;
		try {
			pre = (PreparedStatement)con.prepareStatement(sql);
			for (int i=0; i<param.size();i++) {
				pre.setObject(i+1, param.get(i));
			}
			resultSet = pre.executeQuery();
			
		} catch (SQLException e) {
			e.printStackTrace();
		} 
		return resultSet;
	}
	public static int update(String sql,List<Object> param) throws SQLException { //���º���
		Connection con = DBHelper.getConnection();
		PreparedStatement pre = null;
		int res = 0;
		try {
			pre = (PreparedStatement)con.prepareStatement(sql);
			for (int i=0; i<param.size();i++) {
				pre.setObject(i+1, param.get(i));
			}
			res = pre.executeUpdate();	
		} catch (SQLException e) {
			e.printStackTrace();
		}
		
		return res;
	}
	public static void closeAutoCommit() {
		try {
			con.setAutoCommit(false);
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static void commit() {
		try {
			con.commit();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
	public static void rollback() {
		try {
			con.rollback();
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
